﻿var TripDetails = (function () {
    var User = Class.create({
        initialize: function (fname, lname, email, phone, age, gender) {
            this.fname = fname;
            this.lname = lname;
            this.email = email;
            this.phone = phone;
            this.age = age;
            this.gender = gender;
        },
        toString: function () {
            var stringBuilder = '';
            stringBuilder += ('Име : ' + this.fname + ' ' + this.lname + '\n\t' +
                'E-mail: ' + this.email + '\n\t' +
                'Телефон: ' + this.phone);
            if (this.age) {
                stringBuilder += '\n' + 'Възраст: ' + this.age;
            }
            if (this.gender) {
                stringBuilder += '\n' + 'Пол: ' + this.gender;
            }

            return stringBuilder;
        }
    });

    var Driver = Class.create(User, {
        initialize: function ($super, fname, lname, email, phone, age, gender, vehicle, rating, requirements) {
            $super(fname, lname, email, phone, age, gender);
            this.vehicle = vehicle;
            this.rating = rating;
            this.requirements = requirements;
        },
        toString: function ($super) {
            var stringBuilder = $super();
            if (this.vehicle) {
                stringBuilder += '\n' + 'Превозно средство: '    + this.vehicle.toString();
            }
            if (this.rating) {
                stringBuilder += '\n' + 'Рейтинг: ' + this.rating;
            }
            if (this.requirements) {
                stringBuilder += '\n' + 'Изисквания: ' + this.requirements;
            }

            return stringBuilder;
        }
    });

    var Vehicle = Class.create({
        initialize: function (type, brand, year, seats, fuelConsumption) {
            this.type = type;
            this.brand = brand;
            this.year = year;
            this.seats = seats;
            this.fuelConsumption = fuelConsumption;
        },
        toString: function () {
            var stringBuilder = '';
            if (this.type) {
                stringBuilder += '\n\t' + 'Тип: ' + this.type;
            }
            if (this.brand) {
                stringBuilder += '\n\t' + 'Модел: ' + this.brand;
            }
            if (this.year) {
                stringBuilder += '\n\t' + 'Година на производство: ' + this.year;
            }
            if (this.seats) {
                stringBuilder += '\n\t' + 'Свободни места: ' + this.seats;
            }
            if (this.fuelConsumption) {
                stringBuilder += '\n\t' + 'Разход на гориво(л/100км): ' + this.fuelConsumption;
            }

            return stringBuilder;
        }
    });

    var Trip = new Class.create({
        initialize: function (from, to, dateOfDeparture) {
            this.from = from;
            this.to = to;
            this.dateOfDeparture = dateOfDeparture;
        },
        toString: function () {
            var stringBuilder = '';
            if (this.from) {
                stringBuilder += 'От: ' + this.from;
            }
            if (this.to) {
                stringBuilder += '\n' + 'До: ' + this.to;
            }
            if (this.dateOfDeparture) {
                stringBuilder += '\n' + 'Дата и час: ' + this.dateOfDeparture;
            }

            return stringBuilder;
        }
    });

    var Price = new Class.create({
        initialize: function (value, currency) {
            this.value = value;
            this.currency = currency;
        },
        toString: function () {
            if (this.currency == '$') {
                return this.currency + this.value;
            }
            else {
                return this.value + this.currency;
            }
        }
    });


    var Offer = new Class.create({
        initialize: function (driver, price, trip) {
            this.driver = driver;
            this.price = price;
            this.trip = trip;
        },
        toString: function () {
            return this.driver.toString() + this.price.toString() + this.trip.toString();
        }
    });

    return {
        User: User,
        Driver: Driver,
        Vehicle: Vehicle,
        Trip: Trip,
        Price: Price,
        Offer: Offer
    }
})();

//Demo:
